package com.lightsaber.trade.core.common.tag;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.components.Component;
import org.apache.struts2.views.jsp.ui.AbstractUITag;
import org.springside.modules.utils.spring.SpringContextHolder;

import com.lightsaber.trade.core.entity.sysparam.SysParamete;
import com.lightsaber.trade.core.service.sysparam.SysParameteManager;
import com.opensymphony.xwork2.util.ValueStack;

/*
 * @(#)PageTag.java 1.0 09/11/20
 * 
 * Copyright (c) 2009 Accentrix IT Consulting. All Rights Reserved.
 */
/**
 * Convert code to label
 * 
 * @author LiuJian
 * 
 */
public class Code2LabelTag extends AbstractUITag {

    private static final long serialVersionUID = 1L;

    private String code;

    private String type;

    @Override
    public Component getBean(final ValueStack valueStack, final HttpServletRequest request,
            final HttpServletResponse respose) {
        return new Code2Lebel(valueStack, request, respose);
    }

    @Override
    protected void populateParams() {
        super.populateParams();

        Code2Lebel code2Lebel = (Code2Lebel) component;

        SysParameteManager sysParameteManager = SpringContextHolder
                .getBean(SysParameteManager.class);
        SysParamete SysParamete = sysParameteManager.findByTypeAndCode(type, this.getStack().findString(code));

        if (SysParamete != null) {
            code2Lebel.setLabel(SysParamete.getLabel());
        }else{
            code2Lebel.setLabel("");
        }

    }

    public void setCode(final String code) {
        this.code = code;
    }

    public void setType(String type) {
        this.type = type;
    }

}
